//
//  PersonnelDetailsTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/9/14.
//

#import "PersonnelDetailsTableViewCell.h"
@interface PersonnelDetailsTableViewCell ()
@property (nonatomic ,strong) UILabel * realName;
@property (nonatomic ,strong) UILabel * phone;
@property (nonatomic ,strong) UIView * postNameView;
@property (nonatomic ,strong) UILabel * postName;
@property (nonatomic ,strong) UILabel * taskProgress;
@property (nonatomic ,strong) UILabel * sumCount;
@property (nonatomic ,strong) UILabel * incomplete;
@property (nonatomic ,strong) UILabel * complete;
@property (nonatomic ,strong) UILabel * rwtweviewlab;


@end
@implementation PersonnelDetailsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    MJWeakSelf
    UIView * oneview = [UIView new];
    oneview.addClickBlock(^{
        [weakSelf openPhone];
    });
    oneview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(5) andView:oneview];
    [self addSubview:oneview];
    [oneview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.height.offset(kwt(88));
    }];
    
    UIImageView * userimg = kimageView(@"task_assigner_defaul_staff");
    [DTKTool YJ:kwt(24) andView:userimg];
    [oneview addSubview:userimg];
    [userimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.centerY.offset(0);
        make.height.width.offset(kwt(48));
    }];
    
    UILabel * realName = [DTKTool labelWithText:@"-" andFont:kCFont(19) andTextColor:KcolorHex(@"#222222")];
    self.realName = realName;
    [oneview addSubview:realName];
    [realName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(72));
        make.top.offset(kwt(20));
    }];
    
    UILabel * phone = [DTKTool labelWithText:@"-" andFont:kCFont(16) andTextColor:KcolorHex(@"#3D5FFF")];
    self.phone = phone;
    [oneview addSubview:phone];
    [phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(72));
        make.top.offset(kwt(50));
    }];
    
    UIImageView * phoneimg = kimageView(@"employee_phone_number");
    [oneview addSubview:phoneimg];
    [phoneimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(phone.mas_right).offset(kwt(15));
        make.centerY.equalTo(phone);
        make.width.height.offset(kwt(21));
    }];
    UIView * tweview = [UIView new];
    tweview.backgroundColor = UIColor.whiteColor;
    self.postNameView = tweview;
    [DTKTool YJ:kwt(5) andView:tweview];
    [self addSubview:tweview];
    [tweview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.top.equalTo(oneview.mas_bottom).offset(kwt(10));
        make.right.offset(kwt(-10));
        make.height.offset(kwt(88));
    }];
    
    UILabel * templab = [DTKTool labelWithText:@"岗位职责" andFont:kCFont(17) andTextColor:KcolorHex(@"#222222")];
    [tweview addSubview:templab];
    [templab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.top.offset(kwt(15));
    }];
    
    UILabel * postName = [DTKTool labelWithText:@"--" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    self.postName = postName;
    postName.numberOfLines = 0;
    [tweview addSubview:postName];
    [postName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.top.offset(kwt(44));
        make.width.offset(kwt(330));
    }];
    
    
    UIView * threeview = [UIView new];
    threeview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(5) andView:threeview];
    [self addSubview:threeview];
    [threeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.top.equalTo(tweview.mas_bottom).offset(kwt(10));
        make.right.offset(kwt(-10));
        make.height.offset(kwt(120));
    }];
    
    UILabel * templab1 = [DTKTool labelWithText:@"今日任务完成情况" andFont:kCFont(17) andTextColor:KcolorHex(@"#222222")];
    [threeview addSubview:templab1];
    [templab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.top.offset(kwt(15));
    }];
    
    UIView * rwoneview = [UIView new];
    rwoneview.backgroundColor = KcolorHex(@"#F2F6FF");
    [DTKTool YJ:kwt(5) andView:rwoneview];
    [threeview addSubview:rwoneview];
    [rwoneview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.top.offset(kwt(47));
        make.height.offset(kwt(61));
    }];
    
    UIView * rwtweview = [UIView new];
    rwtweview.backgroundColor = KcolorHex(@"#F2F6FF");
    rwtweview.addClickBlock(^{
        [weakSelf openMyRW];
    });
    [DTKTool YJ:kwt(5) andView:rwtweview];
    [threeview addSubview:rwtweview];
    [rwtweview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(rwoneview.mas_right).offset(kwt(10));
        make.top.offset(kwt(47));
        make.height.offset(kwt(61));
        make.width.equalTo(rwoneview);
    }];
    
    
    UIView * rwthreeview = [UIView new];
    rwthreeview.backgroundColor = KcolorHex(@"#F2F6FF");
    rwthreeview.addClickBlock(^{
        [weakSelf openMyDB];
    });
    [DTKTool YJ:kwt(5) andView:rwthreeview];
    [threeview addSubview:rwthreeview];
    [rwthreeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(rwtweview.mas_right).offset(kwt(10));
        make.top.offset(kwt(47));
        make.height.offset(kwt(61));
        make.width.equalTo(rwtweview);
        
    }];
    
    
    UIView * rwfourview = [UIView new];
    rwfourview.backgroundColor = KcolorHex(@"#F2F6FF");
    rwfourview.addClickBlock(^{
        [weakSelf openMyYWC];
    });
    [DTKTool YJ:kwt(5) andView:rwfourview];
    [threeview addSubview:rwfourview];
    [rwfourview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(rwthreeview.mas_right).offset(kwt(10));
        make.top.offset(kwt(47));
        make.right.offset(kwt(-10));
        make.height.offset(kwt(61));
        make.width.equalTo(rwthreeview);
    }];
    
    UILabel * rwoneviewlab = [DTKTool labelWithText:@"任务进度" andFont:kFont(13) andTextColor:KcolorHex(@"#787A79")];
    [rwoneview addSubview:rwoneviewlab];
    [rwoneviewlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(39));
    }];
    
    UILabel * taskProgress = [DTKTool labelWithText:@"0%" andFont:kCFont(24) andTextColor:KcolorHex(@"#121212")];
    self.taskProgress = taskProgress;
    [rwoneview addSubview:taskProgress];
    [taskProgress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(10));
    }];
    
    
    UILabel * rwtweviewlab = [DTKTool labelWithText:@"他的任务" andFont:kFont(13) andTextColor:KcolorHex(@"#787A79")];
    self.rwtweviewlab = rwtweviewlab;
    [rwtweview addSubview:rwtweviewlab];
    [rwtweviewlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(39));
    }];
    
    UILabel * sumCount = [DTKTool labelWithText:@"0" andFont:kCFont(24) andTextColor:KcolorHex(@"#121212")];
    self.sumCount = sumCount;
    [rwtweview addSubview:sumCount];
    [sumCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(10));
    }];
    
    
    UILabel * rwthreeviewlab = [DTKTool labelWithText:@"待办任务" andFont:kFont(13) andTextColor:KcolorHex(@"#787A79")];
    [rwthreeview addSubview:rwthreeviewlab];
    [rwthreeviewlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(39));
    }];
    
    UILabel * incomplete = [DTKTool labelWithText:@"0" andFont:kCFont(24) andTextColor:KcolorHex(@"#FE0202")];
    self.incomplete = incomplete;
    [rwthreeview addSubview:incomplete];
    [incomplete mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(10));
    }];
    
    UILabel * rwfourviewlab = [DTKTool labelWithText:@"已完成" andFont:kFont(13) andTextColor:KcolorHex(@"#787A79")];
    [rwfourview addSubview:rwfourviewlab];
    [rwfourviewlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(39));
    }];
    
    UILabel * complete = [DTKTool labelWithText:@"0" andFont:kCFont(24) andTextColor:KcolorHex(@"#121212")];
    self.complete = complete;
    [rwfourview addSubview:complete];
    [complete mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(10));
    }];
}
- (void)setModel:(PersonnelDetailsModel *)model{
    _model = model;
    self.realName.text = model.realName;
    self.phone.text = model.phone;
    self.postName.text = model.postNameStr;
    self.taskProgress.text = [NSString stringWithFormat:@"%lu%%",model.taskProgress];
    self.sumCount.text = [NSString stringWithFormat:@"%lu",model.sumCount];
    self.incomplete.text = [NSString stringWithFormat:@"%lu",model.incomplete];
    self.complete.text = [NSString stringWithFormat:@"%lu",model.complete];
    [self.postNameView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.postNameViewH);
    }];
    if([model.userId isEqualToString:[UserInfoModel shared].userID]){
        self.rwtweviewlab.text = @"我的任务";
    }
    
}

- (void)openPhone{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",self.model.phone]] options:nil completionHandler:nil];
}
///完成状态 1:代办 2:已完成 3:已取消

- (void)openMyRW{
    if(self.openRWBlock){
        self.openRWBlock(0);
    }
}

- (void)openMyDB{
    if(self.openRWBlock){
        self.openRWBlock(1);
    }
}
- (void)openMyYWC{
    if(self.openRWBlock){
        self.openRWBlock(2);
    }
}
@end
